import 'package:flutter/material.dart';
import 'package:flutter_chat_ui/models/chat_opening_remarks_model.dart';
import 'package:flutter_chat_ui/pages/chat_room_controller.dart';
import 'package:flutter_chat_ui/utils/utils.dart';
import 'package:flutter_chat_ui/views/chat_message.dart';
// import 'package:flutter_chat_ui/widgets/chat_message.dart';

///
/// 聊天欢迎语组件
///
class ChatElementWelcome extends StatelessWidget {
  final OpeningRemarksData? openingRemarksData;

  const ChatElementWelcome({
    super.key,
    this.openingRemarksData,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.only(top: 24),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          /// 头像
          Padding(
            padding: const EdgeInsets.only(left: 18),
            child: GestureDetector(
              onTap: () {},
              child: Image.asset(
                'assets/icon_robot_avatar.png',
                width: 30,
                height: 30,
              ),
            ),
          ),

          /// 内容
          Expanded(
            child: ChatMessageWidget(
              eventType: MessageEventType.welcome,
              openingRemarksData: openingRemarksData,
            ),
          ),
        ],
      ),
    );
  }
}

///
/// 欢迎内容小组件
///
class ChatWelcomeContentWidget extends StatelessWidget {
  final String? welcomeText;
  final List<String> suggestedQuestions;

  const ChatWelcomeContentWidget({
    super.key,
    this.welcomeText,
    this.suggestedQuestions = const [],
  });

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        /// 欢迎语
        Container(
          margin: const EdgeInsets.only(bottom: 10),
          child: Text(
            welcomeText ?? ''.fixAutoLines(),
            style: const TextStyle(
              fontSize: 16,
              color: Colors.black,
              fontWeight: FontWeight.w500,
            ),
          ),
        ),

        /// 开场推荐问题列表
        Wrap(
          direction: Axis.horizontal,
          spacing: 10,
          runSpacing: 5,
          alignment: WrapAlignment.start,
          children: [
            for (var question in suggestedQuestions)
              TextButton(
                onPressed: () {
                  /// 发送消息
                  ChatRoomController.to.sendMessage(
                    question,
                    conversationId: Utils.lastConversationId ?? '',
                  );
                },
                style: ButtonStyle(
                  textStyle: WidgetStateProperty.all(const TextStyle(fontSize: 15)),
                  backgroundColor: WidgetStateProperty.all(Colors.white),
                  padding: WidgetStateProperty.all(const EdgeInsets.symmetric(horizontal: 10, vertical: 8)),
                  shape: WidgetStateProperty.all(
                    RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(8),
                      side: const BorderSide(color: Color(0xffDDDEE1), width: 0.5),
                    ),
                  ),
                ),
                child: Text(
                  question.fixAutoLines(),
                  style: const TextStyle(color: Color(0xff155AEF)),
                ),
              ),
          ],
        ),
      ],
    );
  }
}
